# Maintainer: Renato Silva <br.renatosilva@gmail.com>

_realname='libsignal-protocol-c'
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=2.3.3
pkgrel=1
pkgdesc='Signal Protocol C Library (mingw-w64)'
url='https://github.com/WhisperSystems/libsignal-protocol-c'
license=(GPL3)
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
options=(!libtool strip staticlibs)
source=(${_realname}-${pkgver}.tar.gz::https://github.com/signalapp/libsignal-protocol-c/archive/v${pkgver}.tar.gz)
sha256sums=('c22e7690546e24d46210ca92dd808f17c3102e1344cd2f9a370136a96d22319d')
makedepends=(${MINGW_PACKAGE_PREFIX}-gcc
             ${MINGW_PACKAGE_PREFIX}-cmake)

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE="Release" \
    -DBUILD_SHARED_LIBS=ON \
    "../${_realname}-${pkgver}"

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
